package com.wuyou.mid;

/**
 * @Description 1017. 负二进制转换
 * @Author 无忧
 * @Date 2023/4/6 14:12
 */
public class BaseNeg2 {


    public static void main(String[] args) {
        int n = 4;

        System.out.println(sol_1(n));

        System.out.println((int)'0');
        System.out.println((int)'9');
    }
    public static String sol_1(int n) {
        StringBuilder s = new StringBuilder();
        int base = -2;
        while (n % base != 0 || n / base != 0) {
            int c = Math.abs(n % base);
            s.insert(0, c);
            n = (n - c) / base;
        }
        return s.length() == 0 ? "0" : s.reverse().toString();
    }
}
